home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Genie / Projects / A-line / Scripts / SourceList.pm < prev    next >
Encoding:
Perl POD Document  |  2000-06-24  |  759 b   |  53 lines

  1. package SourceList;
  2.  
  3. require Exporter;
  4. @ISA = 'Exporter';
  5. @EXPORT = qw(Sources);
  6.  
  7. use strict;
  8.  
  9. # Input file:
  10. #
  11. # | Source:
  12. # |     foo.c
  13. # |     Bar:
  14. # |         bar.c
  15. #
  16. # Output:
  17. #
  18. #     [
  19. #         {
  20. #             FILE => 'foo.c',
  21. #             DIR => ':Source:'
  22. #         }, {
  23. #             FILE => 'bar.c',
  24. #             DIR => ':Source:Bar:'
  25. #         }
  26. #     ]
  27.  
  28. sub Sources {
  29.     local @ARGV = @_;
  30.     my $oldtabs = -1;
  31.     my @path;
  32.     my @SOURCES;
  33.     while (<ARGV>) {
  34.         chop;
  35.         s/^(\t*)//;
  36.         my $tabs = length $1;
  37.         
  38.         if ($tabs > $oldtabs) {
  39.             $tabs - $oldtabs == 1 or die "Too many tabs ($oldtabs -> $tabs)";
  40.         } else {
  41.             $#path -= ($oldtabs - $tabs + 1);
  42.         }
  43.         $oldtabs = $tabs;
  44.         if (!/:$/) {
  45.             my $pathname = join('', ':', @path);
  46.             push @SOURCES, {DIR => $pathname, FILE => $_};
  47.         }
  48.         push @path, $_;
  49.     }
  50.     return \@SOURCES;
  51. }
  52.  
  53.